
#ifndef _BSP_LOOP_H
#define _BSP_LOOP_H

#ifdef __cplusplus
extern "C" {
#endif


#define BSP_LOOP_SAMPLE_TEST_PORT                     GPIOD
#define BSP_LOOP_SAMPLE_TEST_PIN                      GPIO_PIN_7
#define BSP_LOOP_SAMPLE_TEST_CLKENABLE()              __HAL_RCC_GPIOD_CLK_ENABLE()
#define BSP_LOOP_SAMPLE_TEST_FUN                      GPIO_AF_MODE_0

#define BSP_LOOP_SAMPLE_TEST2_PORT                     GPIOB
#define BSP_LOOP_SAMPLE_TEST2_PIN                      GPIO_PIN_8
#define BSP_LOOP_SAMPLE_TEST2_CLKENABLE()              __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_LOOP_SAMPLE_TEST2_FUN                      GPIO_AF_MODE_0

#define BSP_LOOP_LOOPEN_PORT                     GPIOA
#define BSP_LOOP_LOOPEN_PIN                      GPIO_PIN_7
#define BSP_LOOP_LOOPEN_CLKENABLE()              __HAL_RCC_GPIOA_CLK_ENABLE()
#define BSP_LOOP_LOOPEN_FUN                      GPIO_AF_MODE_0
#define BSP_LOOP_LOOPEN_OUT(X)                   HAL_GPIO_WritePin(BSP_LOOP_LOOPEN_PORT,BSP_LOOP_LOOPEN_PIN,(X == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET)

#define BSP_LOOP_LOOPON()                        BSP_LOOP_LOOPEN_OUT(1)
#define BSP_LOOP_LOOPOFF()                       BSP_LOOP_LOOPEN_OUT(0)


#define BSP_LOOP_SEND_PORT                       GPIOA
#define BSP_LOOP_SEND_PIN                        GPIO_PIN_2
#define BSP_LOOP_SEND_CLKENABLE()                __HAL_RCC_GPIOA_CLK_ENABLE()
#define BSP_LOOP_SEND_FUN                        GPIO_AF_MODE_2
#define BSP_LOOP_SEND_CH                         TIM_CHANNEL_1
#define BSP_LOOP_SEND_OUT(X)                     HAL_GPIO_WritePin(BSP_LOOP_SEND_PORT,BSP_LOOP_SEND_PIN,(X == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET)


#define BSP_LOOP_SENDCODE_TIM                    TIM10
#define BSP_LOOP_SENDCODE_TIM_IRQn               TIM10_IRQn
#define BSP_LOOP_SENDCODE_TIM_IRQHandler         TIM10_IRQHandler
#define BSP_LOOP_SENDCODE_TIM_CLK_ENABLE()       __HAL_RCC_BASETIM_CLK_ENABLE()
#define BSP_LOOP_SENDCODE_TIM_DISABLE()          BSP_LOOP_SENDCODE_TIM->CR &= ~(BASETIM_CR_TR)
#define BSP_LOOP_SENDCODE_TIM_ENABLE()           BSP_LOOP_SENDCODE_TIM->CR |= (BASETIM_CR_TR)




#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM                    TIM2B
#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM_IRQn               TIM2B_IRQn
#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM_IRQHandler         TIM2B_IRQHandler
#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM_CLK_ENABLE()       __HAL_RCC_TIM2B_CLK_ENABLE()
#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM_DISABLE()          BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM->CR1 &= ~(TIM_CR1_CEN)
#define BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM_ENABLE()           BSP_LOOP_BACKCODE_TRIGGERSAMPLE_TIM->CR1 |= (TIM_CR1_CEN)


#define BSP_LOOP_BACKCODE_DELAYSAMPLE_TIM                           TIM11
#define BSP_LOOP_BACKCODE_DELAYSAMPLE_IRQn                          TIM11_IRQn
#define BSP_LOOP_BACKCODE_DELAYSAMPLE_IRQHandler                    TIM11_IRQHandler
#define BSP_LOOP_BACKCODE_DELAYSAMPLE_TIM_CLK_ENABLE()              __HAL_RCC_BASETIM_CLK_ENABLE()
#define BSP_LOOP_BACKCODE_DELAYSAMPLE_TIM_DISABLE()                 BSP_LOOP_BACKCODE_DELAYSAMPLE_TIM->CR &= ~(BASETIM_CR_TR)
#define BSP_LOOP_BACKCODE_DELAYSAMPLE_ENABLE()                      BSP_LOOP_BACKCODE_DELAYSAMPLE_TIM->CR |= (BASETIM_CR_TR)





#define BSP_LOOP_TRIGGERSAMPLE_PORT                   GPIOC
#define BSP_LOOP_TRIGGERSAMPLE_PIN                    GPIO_PIN_13
#define BSP_LOOP_TRIGGERSAMPLE_CLKENABLE()            __HAL_RCC_GPIOC_CLK_ENABLE()
#define BSP_LOOP_TRIGGERSAMPLE_FUN                    GPIO_AF_MODE_5      
#define BSP_LOOP_TRIGGERSAMPLE_CH                     TIM_CHANNEL_4   


/*
#define BSP_LOOP_TRIGGERSAMPLE_PORT                   GPIOC
#define BSP_LOOP_TRIGGERSAMPLE_PIN                    GPIO_PIN_13
#define BSP_LOOP_TRIGGERSAMPLE_CLKENABLE()            __HAL_RCC_GPIOC_CLK_ENABLE()
*/   


#define BSP_LOOP_BACKCODE_TRIGGER_IN_PORT                          GPIOB
#define BSP_LOOP_BACKCODE_TRIGGER_IN_PIN                           GPIO_PIN_5
#define BSP_LOOP_BACKCODE_TRIGGER_IN_CLKENABLE()                   __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_LOOP_BACKCODE_TRIGGER_IN_FUN                           GPIO_AF_MODE_0



#define BSP_LOOP_BACKCODE_PORT                   GPIOB
#define BSP_LOOP_BACKCODE_PIN                    GPIO_PIN_2
#define BSP_LOOP_BACKCODE_CLKENABLE()            __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_LOOP_BACKCODE_FUN                    GPIO_MODE_ANALOG      
#define BSP_LOOP_BACKCODE_CH                     HAL_ADC_CHANNEL_16  


#define BSP_LOOP_POWER_VAL_PORT                   GPIOB
#define BSP_LOOP_POWER_VAL_PIN                    GPIO_PIN_11
#define BSP_LOOP_POWER_VAL_CLKENABLE()            __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_LOOP_POWER_VAL_FUN                    GPIO_MODE_ANALOG      
#define BSP_LOOP_POWER_VAL_CH                     HAL_ADC_CHANNEL_17





#ifdef __cplusplus
}
#endif
void bsp_loop_init(void);
void bsp_loop_backcodesampleinit(void);
void bsp_loop_backcodesamplestop(void);
void bsp_loop_backcodesamplestart(void);
#endif /* __ZB32L03x_STARTERKIT_H */


